<?php

namespace App\Common\Traits;

use Illuminate\Support\Facades\Response;

trait ResponseTrait
{

    /**
     * 返回JSON格式数据
     *
     * @param    mixed $data 需要返回的数据
     * @param    int   $code http响应状态码
     * @return   \Illuminate\Http\JsonResponse
     * @internal param $message
     * @author Jinfeihu
     */
    public function success($data, $messages = '', $code = 200,$httpCode=200)
    {
        $response = [
            'status' => $code,
            'data' => $data,
            'message' => $messages
        ];
        return Response::json($response, $httpCode);
    }

    public function errors($data, $messages = '', $code = 400,$httpCode=200)
    {
        $response = [
            'status' => $code,
            'data' => $data,
            'message' => $messages
        ];
        return Response::json($response, $httpCode);
    }

    public function usersInfo()
    {
        return auth('api')->user();
    }
}
